//
//  SHStatusRetweetView.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/23.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit
import SnapKit
class SHStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint: Constraint?
    var statusViewModel: SHStatusViewModel?{
        
        didSet{
            
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            
//            contentLabel.text = statusViewModel?.retweetText
            retweetViewBottomConstraint?.uninstall()
            
            if statusViewModel?.status?.retweeted_status?.pic_urls?.count > 0{
                
                pictureView.pictureInfo = statusViewModel?.status?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(SHStatusCellMargin).constraint
                })
                
                pictureView.hidden = false
            }else{
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(SHStatusCellMargin).constraint
                })
                
                pictureView.hidden = true
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        

        backgroundColor = RGB(237, green: 237, blue: 237)
        addSubview(contentLabel)
        
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(SHStatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(SHStatusCellMargin)
            
            make.leading.equalTo((SCREENW - (3 * cellWH + 2 * cellMargin))/2)
        }
        
        self.snp_makeConstraints { (make) -> Void in
           self.retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(SHStatusCellMargin).constraint
        }
        
    }
    
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: SCREENW - 20)

    private lazy var pictureView: SHStatusPictureView = SHStatusPictureView()
}
